package com.syyc.controller;

import com.syyc.pojo.Content;
import com.syyc.utils.ExcelUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author huimin
 * @date 2021/10/27
 * @apiNote
 */
public class MyAppController {
    public static void main(String[] args) throws IOException {

        List<Content> list = new ArrayList<>();


        // excel标题
        String[] title = {"名称", "类型", "集数"};

        // excel文件名
        String fileName = "B站热播番剧表.xls";

        // sheet名
        String sheetName = "B站热播番剧";

        String[][] content = new String[list.size()][title.length];

        for (int i = 0; i < list.size(); i++) {

            Content con = list.get(i);

            content[i][0] = con.getTitle();
            content[i][1] = con.getBadge();
            content[i][2] = con.getIndexShow();
        }

        // 创建HSSFWorkbook
        HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName, title, content, null);

        File dir = new File("g://excel/");

        if (!dir.exists()) {
            dir.mkdirs();
        }

        fileName = dir + File.separator + fileName;

        BufferedOutputStream bw = new BufferedOutputStream(new FileOutputStream(fileName));

        wb.write(bw);

        // 必须关闭
        bw.close();
    }
}